package cn.gzf.sboot05.controller;


import cn.gzf.sboot05.entity.User;
import cn.gzf.sboot05.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/reg")
    public String reg(User user){
        System.out.println("user = " + user);
        User u = userMapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "用户名已被占用";
        }
        userMapper.insert(user);
        return "注册成功";
    }


    @RequestMapping("/login")
    public String login(User user){
        System.out.println("user = " + user);

        User u = userMapper.selectByUsername(user.getUsername());
        if(u==null){
            return "没有注册，请先注册";
        }
        if(u.getPassword().equals(user.getPassword())){
            return "登录成功";
        }

        return "密码错误";
    }
}
